Relation between Oil, Gold and SP 500

cff plots show that Gold, Oil and SP500 are correlated within each other. The point where h=-0.9 gold and oil has the strongest positive correlation. Moreover, the point where h=-0.09, oil and sp500 has the strongest anti correlation. It is also same for gold and sp500. Additionaly, combined time-series graphs support this claim visually.

Investment Opportunity

Given no experience in finance related predictions, Oil and Gold have ups and downs for past 5 years. Futhermore, the forecasts are suggesting a decrease in oil and gold prices in the next year(2017). However, for SP500 prices, news are all good. ARIMA forecasted that the prices will be up around 2158 dollars. That is why we could expect more return by investing in SP500.

Data Import, Date Modification

getwd()
## [1] "/Users/mkulunyar/Dropbox/NYU/Fall16/BusinessAnalytics/HW_6"
setwd('/Users/mkulunyar/Dropbox/NYU/Fall16/BusinessAnalytics/HW_6')

#Data Export
#investing.com
oil<-read.csv('new_oil_daily.csv', header=TRUE, stringsAsFactors=FALSE)
gold<-read.csv('new_gold_monthly.csv', header=TRUE, stringsAsFactors=FALSE)
sp500<-read.csv('new_sp500_daily.csv', header=TRUE, stringsAsFactors=FALSE)

#DATE
#Date Modification for Oil
head(oil)
##        Date Price  Open  High   Low    Vol. Change..
## 1 25-Nov-16 45.99 47.97 48.02 45.88       -   -4.15%
## 2 24-Nov-16 47.98 48.03 48.26 47.80       -    0.04%
## 3 23-Nov-16 47.96 47.94 48.43 47.40       -   -0.15%
## 4 22-Nov-16 48.03 48.37 49.20 47.17 826.21K    1.14%
## 5 21-Nov-16 47.49 45.83 47.80 45.77  34.92K    3.94%
## 6 18-Nov-16 45.69 44.93 45.77 44.55 155.65K    0.59%
oil$Date <- as.Date(oil$Date, "%d-%B-%y")
oil_sorted<-oil[order(oil$Date, decreasing = FALSE),]
head(oil_sorted)
##            Date Price  Open  High   Low    Vol. Change..
## 1523 2011-01-03 91.55 91.31 92.58 91.21 225.19K    0.19%
## 1522 2011-01-04 89.38 91.50 92.07 88.36 415.52K   -2.37%
## 1521 2011-01-05 90.30 89.29 90.84 88.10 416.91K    1.03%
## 1520 2011-01-06 88.38 90.47 90.71 87.85 440.46K   -2.13%
## 1519 2011-01-07 88.03 88.18 89.48 87.25 444.81K   -0.40%
## 1518 2011-01-10 89.25 89.00 89.98 88.13 430.28K    1.39%
#Date Modification for sp500
head(sp500)
##        Date   Price    Open    High     Low Vol. Change..
## 1 25-Nov-16 2211.25 2205.50 2211.25 2202.50    -    0.26%
## 2 24-Nov-16 2205.50 2199.25 2207.00 2197.75    -    0.27%
## 3 23-Nov-16 2199.50 2200.25 2203.50 2192.25    -   -0.02%
## 4 22-Nov-16 2200.00 2194.00 2203.00 2191.75    -    0.27%
## 5 21-Nov-16 2194.00 2180.50 2196.50 2178.75    -    0.61%
## 6 20-Nov-16 2180.75 2180.00 2181.50 2179.75    -    0.02%
sp500$Date <- as.Date(sp500$Date, "%d-%B-%y")
sp500_sorted<-sp500[order(sp500$Date, decreasing = FALSE),]
head(sp500_sorted)
##            Date   Price    Open    High     Low  Vol. Change..
## 1524 2011-01-04 1265.25 1264.75 1270.00 1258.25 1.78M    0.00%
## 1523 2011-01-05 1271.75 1265.50 1273.75 1255.75 1.80M    0.51%
## 1522 2011-01-06 1270.25 1271.75 1277.00 1266.25 1.61M   -0.12%
## 1521 2011-01-07 1267.50 1269.75 1274.00 1257.75 2.18M   -0.22%
## 1520 2011-01-10 1265.50 1266.25 1268.00 1258.00 1.88M   -0.16%
## 1519 2011-01-11 1270.50 1265.50 1273.75 1264.00 1.66M    0.40%
#Date Modification for gold
head(gold)
##        Date  Price    Open   High    Low   Vol. Change..
## 1 16-Nov-16 1183.0 1277.15 1338.2 1170.5      -   -6.96%
## 2 16-Oct-16 1271.5 1313.50 1316.8 1249.5  5.50K   -3.18%
## 3 16-Sep-16 1313.3 1305.30 1350.5 1301.5  8.18K    0.49%
## 4 16-Aug-16 1306.9 1348.80 1366.0 1306.3 11.45K   -3.12%
## 5 16-Jul-16 1349.0 1324.50 1374.9 1312.8 66.27K    2.32%
## 6 16-Jun-16 1318.4 1215.70 1355.6 1205.4 12.33K    8.53%
gold$Date <- as.Date(gold$Date, "%y-%B-%d")
gold_sorted<-gold[order(gold$Date, decreasing = FALSE),]
head(gold_sorted)
##          Date  Price   Open   High    Low   Vol. Change..
## 71 2011-01-16 1333.8 1415.6 1423.9 1307.7 88.70K   -6.14%
## 70 2011-02-16 1409.3 1333.1 1415.7 1324.9 13.73K    5.66%
## 69 2011-03-16 1438.9 1415.3 1446.9 1385.5 58.55K    2.10%
## 68 2011-04-16 1556.0 1433.4 1568.7 1413.0 15.55K    8.14%
## 67 2011-05-16 1535.9 1572.9 1576.6 1471.0 84.31K   -1.29%
## 66 2011-06-16 1502.3 1535.7 1558.5 1490.7 14.69K   -2.19%
#Time Series
#Oil
#Daily
summary(oil_sorted$Price)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   26.21   49.74   90.86   78.79   98.47  113.90       1
Crude_Oil.ts <- ts(oil_sorted$Price, frequency = 365, start=c(2011))
plot(Crude_Oil.ts)

#Monthly
head(oil_sorted)
##            Date Price  Open  High   Low    Vol. Change..
## 1523 2011-01-03 91.55 91.31 92.58 91.21 225.19K    0.19%
## 1522 2011-01-04 89.38 91.50 92.07 88.36 415.52K   -2.37%
## 1521 2011-01-05 90.30 89.29 90.84 88.10 416.91K    1.03%
## 1520 2011-01-06 88.38 90.47 90.71 87.85 440.46K   -2.13%
## 1519 2011-01-07 88.03 88.18 89.48 87.25 444.81K   -0.40%
## 1518 2011-01-10 89.25 89.00 89.98 88.13 430.28K    1.39%
oil_sorted$MonthYear<-format(oil_sorted$Date, format="%Y-%m")
oil_monthly <- aggregate(oil_sorted$Price ~ MonthYear, oil_sorted, mean, na.rm=TRUE)
oil_monthly
##    MonthYear oil_sorted$Price
## 1    2011-01         89.57850
## 2    2011-02         89.74316
## 3    2011-03        102.98130
## 4    2011-04        110.03850
## 5    2011-05        101.35667
## 6    2011-06         96.28864
## 7    2011-07         97.34050
## 8    2011-08         86.34087
## 9    2011-09         85.61000
## 10   2011-10         86.42810
## 11   2011-11         97.16286
## 12   2011-12         98.57571
## 13   2012-01        100.31850
## 14   2012-02        102.26250
## 15   2012-03        106.20500
## 16   2012-04        103.34600
## 17   2012-05         94.71591
## 18   2012-06         82.40524
## 19   2012-07         87.93143
## 20   2012-08         94.16087
## 21   2012-09         94.55842
## 22   2012-10         89.57087
## 23   2012-11         86.73238
## 24   2012-12         88.24550
## 25   2013-01         94.82857
## 26   2013-02         95.32158
## 27   2013-03         92.95700
## 28   2013-04         92.06773
## 29   2013-05         94.75739
## 30   2013-06         95.80050
## 31   2013-07        104.55522
## 32   2013-08        106.53909
## 33   2013-09        106.26000
## 34   2013-10        100.55261
## 35   2013-11         93.85286
## 36   2013-12         97.89429
## 37   2014-01         94.98348
## 38   2014-02        100.67050
## 39   2014-03        100.50905
## 40   2014-04        102.03476
## 41   2014-05        101.90773
## 42   2014-06        105.14667
## 43   2014-07        102.45130
## 44   2014-08         96.07619
## 45   2014-09         93.16136
## 46   2014-10         84.33913
## 47   2014-11         75.44700
## 48   2014-12         59.14304
## 49   2015-01         47.72609
## 50   2015-02         51.02095
## 51   2015-03         47.85409
## 52   2015-04         54.37864
## 53   2015-05         59.41864
## 54   2015-06         59.82864
## 55   2015-07         51.12957
## 56   2015-08         42.88905
## 57   2015-09         45.44304
## 58   2015-10         46.28955
## 59   2015-11         42.90714
## 60   2015-12         37.32727
## 61   2016-01         31.59571
## 62   2016-02         30.54591
## 63   2016-03         37.96091
## 64   2016-04         41.12476
## 65   2016-05         47.03565
## 66   2016-06         48.85318
## 67   2016-07         45.16591
## 68   2016-08         44.79913
## 69   2016-09         45.17043
## 70   2016-10         49.94000
## 71   2016-11         45.64263
oil_monthly.ts<-ts(oil_monthly$`oil_sorted$Price`, frequency = 12, start = c(2011))
plot(oil_monthly.ts)

#Gold
summary(gold_sorted$Price)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1060    1214    1318    1386    1586    1828
Gold.ts <- ts(gold_sorted$Price, frequency = 12, start=c(2011))
plot(Gold.ts)

#sp500
#Daily
summary(sp500_sorted$Price)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1086    1384    1808    1724    2042    2211
sp500.ts <- ts(sp500_sorted$Price, frequency = 365, start=c(2011))
plot(sp500.ts)

#Monthly
head(sp500_sorted)
##            Date   Price    Open    High     Low  Vol. Change..
## 1524 2011-01-04 1265.25 1264.75 1270.00 1258.25 1.78M    0.00%
## 1523 2011-01-05 1271.75 1265.50 1273.75 1255.75 1.80M    0.51%
## 1522 2011-01-06 1270.25 1271.75 1277.00 1266.25 1.61M   -0.12%
## 1521 2011-01-07 1267.50 1269.75 1274.00 1257.75 2.18M   -0.22%
## 1520 2011-01-10 1265.50 1266.25 1268.00 1258.00 1.88M   -0.16%
## 1519 2011-01-11 1270.50 1265.50 1273.75 1264.00 1.66M    0.40%
sp500_sorted$MonthYear<-format(sp500_sorted$Date, format="%Y-%m")
sp500_monthly <- aggregate(sp500_sorted$Price ~ MonthYear, sp500_sorted, mean, na.rm=TRUE)
sp500_monthly
##    MonthYear sp500_sorted$Price
## 1    2011-01           1279.658
## 2    2011-02           1318.463
## 3    2011-03           1302.150
## 4    2011-04           1326.838
## 5    2011-05           1335.417
## 6    2011-06           1285.120
## 7    2011-07           1321.725
## 8    2011-08           1182.424
## 9    2011-09           1170.988
## 10   2011-10           1201.607
## 11   2011-11           1224.167
## 12   2011-12           1241.336
## 13   2012-01           1296.162
## 14   2012-02           1350.000
## 15   2012-03           1387.232
## 16   2012-04           1382.107
## 17   2012-05           1338.227
## 18   2012-06           1320.260
## 19   2012-07           1354.512
## 20   2012-08           1400.870
## 21   2012-09           1441.917
## 22   2012-10           1430.120
## 23   2012-11           1391.405
## 24   2012-12           1420.217
## 25   2013-01           1474.940
## 26   2013-02           1509.053
## 27   2013-03           1547.354
## 28   2013-04           1564.841
## 29   2013-05           1637.443
## 30   2013-06           1616.822
## 31   2013-07           1661.617
## 32   2013-08           1666.659
## 33   2013-09           1683.723
## 34   2013-10           1713.989
## 35   2013-11           1781.555
## 36   2013-12           1805.376
## 37   2014-01           1818.257
## 38   2014-02           1814.045
## 39   2014-03           1861.919
## 40   2014-04           1858.345
## 41   2014-05           1886.782
## 42   2014-06           1944.060
## 43   2014-07           1967.148
## 44   2014-08           1957.857
## 45   2014-09           1991.453
## 46   2014-10           1930.478
## 47   2014-11           2043.072
## 48   2014-12           2053.148
## 49   2015-01           2022.600
## 50   2015-02           2078.860
## 51   2015-03           2075.933
## 52   2015-04           2087.250
## 53   2015-05           2109.643
## 54   2015-06           2096.971
## 55   2015-07           2087.220
## 56   2015-08           2035.607
## 57   2015-09           1940.013
## 58   2015-10           2017.148
## 59   2015-11           2077.488
## 60   2015-12           2051.305
## 61   2016-01           1906.899
## 62   2016-02           1897.750
## 63   2016-03           2018.219
## 64   2016-04           2069.345
## 65   2016-05           2065.033
## 66   2016-06           2079.795
## 67   2016-07           2138.154
## 68   2016-08           2174.500
## 69   2016-09           2155.520
## 70   2016-10           2137.179
## 71   2016-11           2158.988
sp500_monthly.ts<-ts(sp500_monthly$`sp500_sorted$Price`, frequency = 12, start = c(2011))
plot(sp500_monthly.ts)

Decomposition, Combining Time Series by using Oil and SP500 monthly

#Decomposition
#Gold
Gold.ts.d<-decompose(Gold.ts)
plot(Gold.ts.d)

#Oil
Crude_Oil.ts.d<-decompose(oil_monthly.ts)
#sp500
sp500.ts.d<-decompose(sp500_monthly.ts)
plot(sp500.ts.d)

#Combining Oil, Gold and sp500
library(xts)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric

#Oil-Gold
oil_gold <- cbind(oil_monthly.ts, Gold.ts)
plot(oil_gold)

#gold-sp500
gold_sp500 <- cbind(Gold.ts, sp500_monthly.ts)
plot(gold_sp500)

#oil-sp500
oil_sp500 <- cbind(oil_monthly.ts, sp500_monthly.ts)
plot(oil_sp500)

#Some Visuals
ts.plot(oil_monthly.ts, Gold.ts,gpars= list(col=rainbow(10)))

ts.plot(oil_monthly.ts, sp500_monthly.ts,gpars= list(col=rainbow(10)))

ts.plot(Gold.ts, sp500_monthly.ts,gpars= list(col=rainbow(10)))

Cross-Correlation (cff graphs)

require(graphics)
#Cross Correlation Plots, Lets see what effects oil prices
ccf(Gold.ts, oil_monthly.ts, ylab = "cross-correlation")

ccf(sp500_monthly.ts, oil_monthly.ts, ylab = "cross-correlation")

ccf(sp500_monthly.ts, Gold.ts, ylab = "cross-correlation")

Smoothing and Forecasting using Holt’s and ARIMA for a horizon of 12 months

#oil
#smoothing
oil_monthly.holt.T <- HoltWinters(oil_monthly.ts, gamma=TRUE)
oil_monthly.holt.T
## Holt-Winters exponential smoothing with trend and additive seasonal component.
## 
## Call:
## HoltWinters(x = oil_monthly.ts, gamma = TRUE)
## 
## Smoothing parameters:
##  alpha: 0.7529772
##  beta : 0
##  gamma: TRUE
## 
## Coefficients:
##            [,1]
## a    57.1546228
## b    -0.1563476
## s1   -8.1454262
## s2   -3.8650927
## s3    4.2180103
## s4    9.2784438
## s5   11.2650742
## s6    9.7780399
## s7    2.1196298
## s8   -2.8106607
## s9   -5.3793443
## s10  -6.2559619
## s11  -8.6591052
## s12 -11.5119912
plot(oil_monthly.holt.T)

oil_monthly.holt.F <- HoltWinters(oil_monthly.ts, gamma=FALSE)
oil_monthly.holt.F
## Holt-Winters exponential smoothing with trend and without seasonal component.
## 
## Call:
## HoltWinters(x = oil_monthly.ts, gamma = FALSE)
## 
## Smoothing parameters:
##  alpha: 1
##  beta : 0.008765806
##  gamma: FALSE
## 
## Coefficients:
##         [,1]
## a 45.6426316
## b -0.2417478
plot(oil_monthly.holt.F)

#forecasting, holt, horizon is 12 months
library(forecast)
## Loading required package: timeDate
## This is forecast 7.3
## 
## Attaching package: 'forecast'
## The following object is masked _by_ '.GlobalEnv':
## 
##     gold
oil_monthly.forecasts <- forecast.HoltWinters(oil_monthly.holt.T, h=12)  
plot.forecast(oil_monthly.forecasts)

oil_monthly.forecasts <- forecast.HoltWinters(oil_monthly.holt.F, h=12)  
plot.forecast(oil_monthly.forecasts)

#ARIMA
oil_monthly.arima<-arima(oil_monthly.ts, c(0,0,0))  
oil_monthly.arima.forecasts <- forecast.Arima(oil_monthly.arima, h=12)
oil_monthly.arima.forecasts
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Dec 2016       79.11551 47.70924 110.5218 31.08377 127.1473
## Jan 2017       79.11551 47.70924 110.5218 31.08377 127.1473
## Feb 2017       79.11551 47.70924 110.5218 31.08377 127.1473
## Mar 2017       79.11551 47.70924 110.5218 31.08377 127.1473
## Apr 2017       79.11551 47.70924 110.5218 31.08377 127.1473
## May 2017       79.11551 47.70924 110.5218 31.08377 127.1473
## Jun 2017       79.11551 47.70924 110.5218 31.08377 127.1473
## Jul 2017       79.11551 47.70924 110.5218 31.08377 127.1473
## Aug 2017       79.11551 47.70924 110.5218 31.08377 127.1473
## Sep 2017       79.11551 47.70924 110.5218 31.08377 127.1473
## Oct 2017       79.11551 47.70924 110.5218 31.08377 127.1473
## Nov 2017       79.11551 47.70924 110.5218 31.08377 127.1473
plot(oil_monthly.arima.forecasts)

oil_monthly.arima<-arima(oil_monthly.ts, c(0,1,0))  
oil_monthly.arima.forecasts <- forecast.Arima(oil_monthly.arima, h=12)
oil_monthly.arima.forecasts
##          Point Forecast    Lo 80    Hi 80     Lo 95    Hi 95
## Dec 2016       45.64263 38.29897 52.98630 34.411467 56.87380
## Jan 2017       45.64263 35.25712 56.02814 29.759367 61.52590
## Feb 2017       45.64263 32.92303 58.36223 26.189685 65.09558
## Mar 2017       45.64263 30.95530 60.32996 23.180303 68.10496
## Apr 2017       45.64263 29.22170 62.06356 20.528985 70.75628
## May 2017       45.64263 27.65440 63.63086 18.132010 73.15325
## Jun 2017       45.64263 26.21312 65.07214 15.927764 75.35750
## Jul 2017       45.64263 24.87161 66.41365 13.876102 77.40916
## Aug 2017       45.64263 23.61164 67.67362 11.949139 79.33612
## Sep 2017       45.64263 22.41993 68.86533 10.126572 81.15869
## Oct 2017       45.64263 21.28646 69.99881  8.393074 82.89219
## Nov 2017       45.64263 20.20343 71.08183  6.736738 84.54853
plot(oil_monthly.arima.forecasts)

oil_monthly.arima<-arima(oil_monthly.ts, c(1,1,0))  
oil_monthly.arima.forecasts <- forecast.Arima(oil_monthly.arima, h=12)
oil_monthly.arima.forecasts
##          Point Forecast     Lo 80    Hi 80      Lo 95    Hi 95
## Dec 2016       44.19591 37.289947 51.10187 33.6341521 54.75767
## Jan 2017       43.70887 32.180580 55.23715 26.0778741 61.33986
## Feb 2017       43.54490 28.274902 58.81490 20.1914534 66.89835
## Mar 2017       43.48970 25.083430 61.89597 15.3397392 71.63966
## Apr 2017       43.47112 22.346727 64.59551 11.1641495 75.77809
## May 2017       43.46486 19.921094 67.00863  7.4577759 79.47195
## Jun 2017       43.46276 17.721986 69.20353  4.0956449 82.82987
## Jul 2017       43.46205 15.696314 71.22778  0.9980223 85.92607
## Aug 2017       43.46181 13.808674 73.11494 -1.8887466 88.81236
## Sep 2017       43.46173 12.034212 74.88924 -4.6025099 91.52597
## Oct 2017       43.46170 10.354725 76.56868 -7.1710490 94.09445
## Nov 2017       43.46169  8.756421 78.16696 -9.6154397 96.53882
plot(oil_monthly.arima.forecasts)

#gold
#smoothing
Gold.holt.T <- HoltWinters(Gold.ts, gamma=TRUE)
## Warning in HoltWinters(Gold.ts, gamma = TRUE): optimization difficulties:
## ERROR: ABNORMAL_TERMINATION_IN_LNSRCH
Gold.holt.T
## Holt-Winters exponential smoothing with trend and additive seasonal component.
## 
## Call:
## HoltWinters(x = Gold.ts, gamma = TRUE)
## 
## Smoothing parameters:
##  alpha: 0.6822217
##  beta : 0.007896061
##  gamma: TRUE
## 
## Coefficients:
##            [,1]
## a   1211.400726
## b      1.014738
## s1   -25.061771
## s2    24.128854
## s3    46.519344
## s4     4.355240
## s5    -3.757114
## s6   -86.569355
## s7   -75.189104
## s8   -91.861003
## s9   -33.893129
## s10    1.587652
## s11    3.998167
## s12  -28.400726
plot(Gold.holt.T)

Gold.holt.F <- HoltWinters(Gold.ts, gamma=FALSE)
Gold.holt.F
## Holt-Winters exponential smoothing with trend and without seasonal component.
## 
## Call:
## HoltWinters(x = Gold.ts, gamma = FALSE)
## 
## Smoothing parameters:
##  alpha: 0.7350228
##  beta : 0.1651861
##  gamma: FALSE
## 
## Coefficients:
##          [,1]
## a 1212.153807
## b   -7.999157
plot(Gold.holt.F)

#forecasting, holt, horizon is 12 months
library(forecast)
Gold.forecasts <- forecast.HoltWinters(Gold.holt.T, h=12)  
plot.forecast(Gold.forecasts)

Gold.forecasts <- forecast.HoltWinters(Gold.holt.F, h=12)  
plot.forecast(Gold.forecasts)

#ARIMA
Gold.arima<-arima(Gold.ts, c(0,0,0))  
Gold.arima.forecasts <- forecast.Arima(Gold.arima, h=12)
Gold.arima.forecasts
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Dec 2016        1386.07 1116.446 1655.695 973.7159 1798.425
## Jan 2017        1386.07 1116.446 1655.695 973.7159 1798.425
## Feb 2017        1386.07 1116.446 1655.695 973.7159 1798.425
## Mar 2017        1386.07 1116.446 1655.695 973.7159 1798.425
## Apr 2017        1386.07 1116.446 1655.695 973.7159 1798.425
## May 2017        1386.07 1116.446 1655.695 973.7159 1798.425
## Jun 2017        1386.07 1116.446 1655.695 973.7159 1798.425
## Jul 2017        1386.07 1116.446 1655.695 973.7159 1798.425
## Aug 2017        1386.07 1116.446 1655.695 973.7159 1798.425
## Sep 2017        1386.07 1116.446 1655.695 973.7159 1798.425
## Oct 2017        1386.07 1116.446 1655.695 973.7159 1798.425
## Nov 2017        1386.07 1116.446 1655.695 973.7159 1798.425
plot(Gold.arima.forecasts)

Gold.arima<-arima(Gold.ts, c(0,1,0))  
Gold.arima.forecasts <- forecast.Arima(Gold.arima, h=12)
Gold.arima.forecasts
##          Point Forecast     Lo 80    Hi 80     Lo 95    Hi 95
## Dec 2016           1183 1084.4047 1281.595 1032.2115 1333.789
## Jan 2017           1183 1043.5652 1322.435  969.7528 1396.247
## Feb 2017           1183 1012.2279 1353.772  921.8266 1444.173
## Mar 2017           1183  985.8094 1380.191  881.4229 1484.577
## Apr 2017           1183  962.5342 1403.466  845.8266 1520.173
## May 2017           1183  941.4918 1424.508  813.6450 1552.355
## Jun 2017           1183  922.1413 1443.859  784.0510 1581.949
## Jul 2017           1183  904.1303 1461.870  756.5056 1609.494
## Aug 2017           1183  887.2140 1478.786  730.6344 1635.366
## Sep 2017           1183  871.2142 1494.786  706.1648 1659.835
## Oct 2017           1183  855.9963 1510.004  682.8910 1683.109
## Nov 2017           1183  841.4558 1524.544  660.6532 1705.347
plot(Gold.arima.forecasts)

Gold.arima<-arima(Gold.ts, c(1,1,0))  
Gold.arima.forecasts <- forecast.Arima(Gold.arima, h=12)
Gold.arima.forecasts
##          Point Forecast     Lo 80    Hi 80     Lo 95    Hi 95
## Dec 2016       1199.990 1103.2206 1296.759 1051.9942 1347.985
## Jan 2017       1196.728 1072.3166 1321.140 1006.4571 1386.999
## Feb 2017       1197.354 1048.4830 1346.226  969.6753 1425.033
## Mar 2017       1197.234 1027.7184 1366.750  937.9822 1456.486
## Apr 2017       1197.257 1009.2948 1385.220  909.7936 1484.721
## May 2017       1197.253  992.5090 1401.996  884.1242 1510.381
## Jun 2017       1197.254  977.0016 1417.506  860.4072 1534.100
## Jul 2017       1197.253  962.5158 1431.991  838.2532 1556.254
## Aug 2017       1197.253  948.8735 1445.633  817.3892 1577.118
## Sep 2017       1197.253  935.9425 1458.564  797.6129 1596.894
## Oct 2017       1197.253  923.6219 1470.885  778.7701 1615.737
## Nov 2017       1197.253  911.8326 1482.674  760.7400 1633.767
plot(Gold.arima.forecasts)

#sp500
#smoothing
sp500_monthly.holt.T <- HoltWinters(sp500_monthly.ts, gamma=TRUE)
sp500_monthly.holt.T
## Holt-Winters exponential smoothing with trend and additive seasonal component.
## 
## Call:
## HoltWinters(x = sp500_monthly.ts, gamma = TRUE)
## 
## Smoothing parameters:
##  alpha: 0.6991165
##  beta : 0.001792776
##  gamma: TRUE
## 
## Coefficients:
##            [,1]
## a   2175.597190
## b      9.692326
## s1   -31.951821
## s2   -64.888173
## s3     3.968325
## s4    84.405185
## s5    90.442670
## s6    70.785981
## s7    42.859576
## s8    48.193019
## s9    16.866959
## s10  -37.086236
## s11  -46.622629
## s12  -16.609690
plot(sp500_monthly.holt.T)

sp500_monthly.holt.F <- HoltWinters(sp500_monthly.ts, gamma=FALSE)
sp500_monthly.holt.F
## Holt-Winters exponential smoothing with trend and without seasonal component.
## 
## Call:
## HoltWinters(x = sp500_monthly.ts, gamma = FALSE)
## 
## Smoothing parameters:
##  alpha: 1
##  beta : 0.05385708
##  gamma: FALSE
## 
## Coefficients:
##         [,1]
## a 2158.98750
## b   11.45743
plot(sp500_monthly.holt.F)

#forecasting, holt, horizon is 12 months
library(forecast)
sp500_monthly.forecasts <- forecast.HoltWinters(sp500_monthly.holt.T, h=12)  
plot.forecast(sp500_monthly.forecasts)

sp500_monthly.forecasts <- forecast.HoltWinters(sp500_monthly.holt.F, h=12)  
plot.forecast(sp500_monthly.forecasts)

#ARIMA
sp500_monthly.arima<-arima(sp500_monthly.ts, c(0,0,0))  
sp500_monthly.arima.forecasts <- forecast.Arima(sp500_monthly.arima, h=12)
sp500_monthly.arima.forecasts
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Dec 2016       1717.948 1299.067 2136.828 1077.326 2358.569
## Jan 2017       1717.948 1299.067 2136.828 1077.326 2358.569
## Feb 2017       1717.948 1299.067 2136.828 1077.326 2358.569
## Mar 2017       1717.948 1299.067 2136.828 1077.326 2358.569
## Apr 2017       1717.948 1299.067 2136.828 1077.326 2358.569
## May 2017       1717.948 1299.067 2136.828 1077.326 2358.569
## Jun 2017       1717.948 1299.067 2136.828 1077.326 2358.569
## Jul 2017       1717.948 1299.067 2136.828 1077.326 2358.569
## Aug 2017       1717.948 1299.067 2136.828 1077.326 2358.569
## Sep 2017       1717.948 1299.067 2136.828 1077.326 2358.569
## Oct 2017       1717.948 1299.067 2136.828 1077.326 2358.569
## Nov 2017       1717.948 1299.067 2136.828 1077.326 2358.569
plot(sp500_monthly.arima.forecasts)

sp500_monthly.arima<-arima(sp500_monthly.ts, c(0,1,0))  
sp500_monthly.arima.forecasts <- forecast.Arima(sp500_monthly.arima, h=12)
sp500_monthly.arima.forecasts
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Dec 2016       2158.988 2097.577 2220.398 2065.069 2252.906
## Jan 2017       2158.988 2072.140 2245.835 2026.166 2291.809
## Feb 2017       2158.988 2052.622 2265.353 1996.315 2321.660
## Mar 2017       2158.988 2036.167 2281.808 1971.150 2346.825
## Apr 2017       2158.988 2021.670 2296.305 1948.979 2368.996
## May 2017       2158.988 2008.564 2309.411 1928.934 2389.041
## Jun 2017       2158.988 1996.511 2321.464 1910.502 2407.473
## Jul 2017       2158.988 1985.293 2332.682 1893.345 2424.630
## Aug 2017       2158.988 1974.757 2343.218 1877.231 2440.744
## Sep 2017       2158.988 1964.791 2353.184 1861.990 2455.985
## Oct 2017       2158.988 1955.313 2362.662 1847.494 2470.481
## Nov 2017       2158.988 1946.256 2371.719 1833.643 2484.332
plot(sp500_monthly.arima.forecasts)

sp500_monthly.arima<-arima(sp500_monthly.ts, c(1,1,0))  
sp500_monthly.arima.forecasts <- forecast.Arima(sp500_monthly.arima, h=12)
sp500_monthly.arima.forecasts
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Dec 2016       2161.273 2100.206 2222.339 2067.879 2254.666
## Jan 2017       2161.512 2070.514 2252.511 2022.342 2300.682
## Feb 2017       2161.537 2047.857 2275.218 1987.678 2335.396
## Mar 2017       2161.540 2028.968 2294.112 1958.789 2364.291
## Apr 2017       2161.540 2012.448 2310.632 1933.524 2389.556
## May 2017       2161.540 1997.584 2325.496 1910.791 2412.289
## Jun 2017       2161.540 1983.960 2339.120 1889.955 2433.126
## Jul 2017       2161.540 1971.309 2351.772 1870.607 2452.474
## Aug 2017       2161.540 1959.448 2363.632 1852.467 2470.613
## Sep 2017       2161.540 1948.246 2374.834 1835.335 2487.745
## Oct 2017       2161.540 1937.604 2385.477 1819.059 2504.021
## Nov 2017       2161.540 1927.445 2395.636 1803.522 2519.559
plot(sp500_monthly.arima.forecasts)